﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LibrarySolution.Frm;
using LibrarySolution.ComMethod;
using LibrarySolution.DAO.基础;
using LibrarySolution.Model.基础;

namespace LibrarySolution
{
    public partial class FrmMain : Form
    {
        #region 属性
        YhDao yhDao;
        #endregion

        #region 构造器
        public FrmMain()
        {
            InitializeComponent();
            if (GlobalVar.YhEnter == true)
            {
                this.treeView1.Nodes[4].Remove();
                this.treeView1.Nodes[3].Remove();
                this.treeView1.Nodes[2].Nodes[0].Remove();
                this.treeView1.Nodes[1].Nodes[2].Remove();
                this.treeView1.Nodes[1].Nodes[0].Remove();
                this.treeView1.Nodes[0].Nodes[1].Remove();
                this.treeView1.Nodes[0].Nodes[0].Remove();
                return;
            }
            if (GlobalVar.NoGly == true)
            {
                this.treeView1.Nodes[4].Nodes[0].Text = "个人信息";
                this.treeView1.Nodes[1].Nodes[3].Remove();
            }
            if (GlobalVar.SpGly == true) { this.treeView1.Nodes[4].Nodes[0].Text = "管理员添删操作"; }
            this.treeView1.Nodes[0].Nodes[2].Remove();
        }
        #endregion

        #region 事件
        private void LblYhxx_Click(object sender, EventArgs e)
        {
            if (GlobalVar.YhEnter != true)
                FrmYhxx.GetInstance().Show();
            else
            {
                String yhNo;
                YhDao yhDao = new YhDao();
                yhNo = GlobalVar.YhxxEntity.yh_no;
                GlobalVar.YhxxEntity =yhDao.getYhxxByNo(yhNo,"0");
                FrmYhxxModify.GetInstance().ShowDialog();
            }
        }

        private void LblBkxx_Click(object sender, EventArgs e)
        {
            FrmBkxx.GetInstance().Show();
        }

        private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void LblGlyxx_Click(object sender, EventArgs e)
        {
            if (GlobalVar.SpGly == true)
                FrmGlyxx.GetInstance().Show();
            else
            {
                GlyDao glyDao = new GlyDao();
                GlyEntity glyEntity = new GlyEntity();
                glyEntity.gly_code = GlobalVar.GlyEntity.gly_code;
                GlobalVar.GlyEntity = glyDao.getGlyxxByCode(glyEntity);
                FrmGlyxxModify.GetInstance().ShowDialog();
            }

        }

        private void LblDJ_Click(object sender, EventArgs e)
        {
            FrmYhjb.GetInstance().Show();
        }

        private void LblJS_Click(object sender, EventArgs e)
        {
            FrmJyts.GetInstance().Show();
        }

        private void LblJsjl_Click(object sender, EventArgs e)
        {
            FrmJsjl.GetInstance().Show();
        }

        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            switch (e.Node.Text)
            {
                case "图书操作":
                    FrmBkxx.GetInstance().Show();
                    break;
                case"图书丢失标记":
                    FrmTsbj.GetInstance().Show();
                    break;
                case "用户添改操作":
                    FrmYhxx.GetInstance().Show();
                    GlobalVar.YhEnter = true;
                    break;
                case"密码设置":
                    if (!String.IsNullOrEmpty(GlobalVar.YhxxEntity.yh_pwd))
                    { FrmChangPwd.GetInstance(GlobalVar.YhxxEntity.yh_no).Show(); GlobalVar.YhEnter = true; return; }
                    FrmPeLo.GetInstance().Show();
                    break;                
                case "用户级别":
                    FrmYhjb.GetInstance().Show();
                    break;
                case "借阅图书":
                    FrmKfxx.isModify = true;
                    FrmJyts.GetInstance().Show();
                    break;
                case "续借图书":
                    FrmXjts.GetInstance().Show();
                    break;
                case"归还图书":
                    FrmTsgh.GetInstance().Show();
                    break;
                case "管理员添删操作":
                    FrmGlyxx.GetInstance().Show();
                    break;
                case"超期丢失处理":
                    FrmKfxx.GetInstance().Show();
                    break;
                case "个人信息":
                    if (GlobalVar.NoGly == true)
                    {
                        GlyDao glyDao = new GlyDao();
                        GlyEntity glyEntity = new GlyEntity();
                        glyEntity.gly_code = GlobalVar.GlyEntity.gly_code;
                        GlobalVar.GlyEntity = glyDao.getGlyxxByCode(glyEntity);
                        FrmGlyxxModify.GetInstance().ShowDialog();
                    }
                    else
                    {
                        String yhNo;
                        yhDao = new YhDao();
                        yhNo = GlobalVar.YhxxEntity.yh_no;
                        GlobalVar.YhxxEntity = yhDao.getYhxxByNo(yhNo, "0");
                        FrmYhxxModify.GetInstance().ShowDialog();
                    }
                    break;
                case"图书检索":
                    FrmBkxx.GetInstance().Show();
                    break;
            }
        }        
        #endregion
    }
}
